package com.o2opuzi.lib.web;

import java.util.LinkedHashMap;
import java.util.regex.Pattern;

import org.springframework.util.StringUtils; 

import com.o2opuzi.lib.db.Converter;


public class MapParam extends LinkedHashMap<String, Object>{

	private static final long serialVersionUID = -5812109600344903573L;
	
	
	/**
	 * 判断是否为空
	 * @author yue han jiang
	 * @param name
	 * @return
	 */
	public boolean isEmpty(String attribute){
		return StringUtils.isEmpty(get(attribute));
	}
	
	/**
	 * 正则匹配
	 * @author yue han jiang
	 * @param attribute
	 * @param regex
	 * @return
	 */
	public boolean match(String attribute,String regex){
		 return Pattern.matches(regex, get(attribute).toString());
	}
	
	public Integer getInteger(String attribute){
		Object value = get(attribute);
		if(value.getClass().equals(Integer.class) || value.getClass().equals(int.class))
			return (Integer)value;
		return Converter.convert(Integer.class, value.toString());
	}
	
	public Long getLong(String attribute){
		Object value = get(attribute);
		if(value.getClass().equals(Long.class) || value.getClass().equals(long.class))
			return (Long)value;
		return Converter.convert(Long.class, value.toString());
	}
	
	
}
